// 拼接请求前缀
$.ajaxPrefilter(function (option) {
  // 什么时候触发
  console.log(option);
  option.url = 'http://api-breakingnews-web.itheima.net' + option.url;
  // 添加统一的请求头配置
  if (option.url.includes('/my/')) {
    option.headers = {
      Authorization: localStorage.token || '',
    };
  }

  option.complete = function (res) {
    if (
      res.responseJSON.status === 1 &&
      res.responseJSON.message === '身份认证失败！'
    ) {
      localStorage.removeItem('token');
      location.href = '/login.html';
    }
  };
});
